package Demo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.function.Function;
import java.util.function.IntFunction;

public class Test3 {
    public static void main(String[] args) {
        Student1 s1 = new Student1("a", 12);
        Student1 s2 = new Student1("b", 14);

        ArrayList<Student1> list = new ArrayList<>();
        Collections.addAll(list, s1, s2);

//        String[] arr = list.stream()
//                .map(new Function<Student1, String>() {
//                    @Override
//                    public String apply(Student1 s) {
//                        return s.getName();
//                    }
//                })
//                .toArray(String[]::new);
//
//        System.out.println(Arrays.toString(arr));

        String[] srr = list.stream()
                .map(Student1::getName)
                .toArray(String[]::new);

        System.out.println(Arrays.toString(srr));
    }
}

class Student1 {
    private String name;
    private int age;

    public Student1() {
    }

    //    public Student1(String str) {
//        String[] arr = str.split(",");
//        this.name = arr[0];
//
//    }
    public Student1(String name, int age) {
        this.name = name;
        this.age = age;
    }

    /**
     * 获取
     *
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     *
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     *
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    public String toString() {
        return "Student1{name = " + name + ", age = " + age + "}";
    }
}